import {fileURLToPath, URL} from 'node:url'

import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import {resolve} from 'path'

// https://vitejs.dev/config/
export default defineConfig({
    base: process.env.NODE_ENV === 'production' ? './' : '/',
    plugins: [vue(), vueJsx()],
    server: {
        open: false,
        port: 5173,
        // proxy: {
        //     '/api': {
        //         //target: 'http://localhost:5001', // 后台地址
        //         target: 'http://localhost', // 后台地址
        //         changeOrigin: true,
        //         rewrite: (path) => path.replace(/^\/api/, '')
        //     }
        // }
    },
    css: {
        preprocessorOptions: {
            less: {
                // 这里可以配置LESS的全局变量等
            }
        }
    },
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src/renderer', import.meta.url))
        }
    },
    build: {
        outDir: 'dist', // 输出目录
        assetsDir: 'assets', // 静态资源目录
        rollupOptions: {
            input: {
                main: resolve(__dirname, 'index.html'),
                login: resolve(__dirname, 'login.html')
            },
            output: {
                entryFileNames: `assets/[name].js`,
                chunkFileNames: `assets/[name].js`,
                assetFileNames: `assets/[name].[ext]`
            }
        }
    },
    define: { 'process.env': {} }
})
